import json

import jsonpath
import requests
from retrying import retry
from pprint import pprint


class aiyou(object):
    def __init__(self):
        self.i = 0

    @retry(stop_max_attempt_number=5)
    def meiju(self):
        pprint('wawaoo')
        url = 'https://m.douban.com/rexxar/api/v2/subject_collection/filter_tv_american_hot/items?'
        headers = {
            "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1",
            "Referer": "Referer: https://m.douban.com/tv/american",
        }
        """  
    start: 0
    count: 50
        """
        params = {
            'start': start,
            "count": 50,
        }
        r = requests.get(url=url, headers=headers, timeout=10, params=params, verify=False)
        data = json.loads(r.text)
        result = jsonpath.jsonpath(data, '$..title')
        pprint(result)
        self.i += 50
        print(self.i)


if __name__ == '__main__':
    try:
        aiyou = aiyou()
        for start in range(0, 1050, 50):
            aiyou.meiju()
    except  Exception as e:
        pprint(e)
        pprint('shibai')
